package com.five.monkey.feign.consumer.controller;

import com.five.monkey.feign.consumer.client.GraphFeignClient;
import com.five.monkey.vo.CommonVo;
import com.five.monkey.vo.GraphVo;
import com.five.monkey.vo.PageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 狻猊
 * @date 2021/8/10 下午2:26
 */
@RestController
@RequestMapping("/consumer/graph")
public class ConsumerGraphController {

    @Autowired
    private GraphFeignClient graphFeignClient;

    @GetMapping("/find/by/{id}")
    public CommonVo<GraphVo> findById(@PathVariable("id") Long id) {
        return graphFeignClient.findById(id);
    }

    @GetMapping("/find/by/user/{userId}")
    public CommonVo<List<GraphVo>> findByUserId(@PathVariable("userId") Long userId) {
        return graphFeignClient.findByUserId(userId);
    }

    @PostMapping("/save/to/elasticsearch")
    public CommonVo<GraphVo> saveToElasticsearch(@RequestBody GraphVo graphVo) {
        return graphFeignClient.saveToElasticsearch(graphVo);
    }

    @GetMapping("/find/by/{id}/elasticsearch")
    public CommonVo<GraphVo> findByIdFromElasticsearch(@PathVariable("id") Long id) {
        return graphFeignClient.findByIdFromElasticsearch(id);
    }

    @DeleteMapping("/delete/by/{id}/elasticsearch")
    public CommonVo<Boolean> deleteByIdFromElasticsearch(@PathVariable("id") Long id) {
        return graphFeignClient.deleteByIdFromElasticsearch(id);
    }

    @GetMapping("/find/all/elasticsearch")
    public CommonVo<List<GraphVo>> findAllFromElasticsearch() {
        return graphFeignClient.findAllFromElasticsearch();
    }

    @GetMapping("/page/by/{status}/elasticsearch")
    public CommonVo<PageVo<GraphVo>> pageByStatusFromElasticsearch(@PathVariable("status") Integer status, @RequestParam(value = "page") int page,
                                                                   @RequestParam(value = "size", required = false, defaultValue = "10") int size) {
        return graphFeignClient.pageByStatusFromElasticsearch(status, page, size);
    }

    @GetMapping("/list/by/{status}/elasticsearch")
    public CommonVo<List<GraphVo>> listByStatusFromElasticsearch(@PathVariable("status") Integer status) {
        return graphFeignClient.listByStatusFromElasticsearch(status);
    }
}
